package com.gxa.web_admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxa.common.vo.JsonResult;
import com.gxa.common.vo.R;
import com.gxa.modules.pojo.Enterprise_Customer;
import com.gxa.modules.service.FirmCustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/customers")
public class FirmCustomerController {

    @Autowired
    private FirmCustomerService firmCustomerService;
    /**
     * 分页查询企业客户列表所有数据
     * @return
     */
    @GetMapping("/findFirmCustomerList")
    public JsonResult findFirmCustomerList(Long currentPage, Long pageSize){
        JsonResult jr = new JsonResult();
        try{
            long totalSize = firmCustomerService.count();
            jr.setCount((int) totalSize);
            Long start =(currentPage-1)*pageSize;
            Long off = pageSize;
            Page<Enterprise_Customer> page =new Page(start,off);
            Page<Enterprise_Customer> enterprise_customerPage = firmCustomerService.page(page);
            jr.setCode(200);
            jr.setMsg("查询成功");
            jr.setData(enterprise_customerPage);
        }catch (Exception e){
            e.printStackTrace();
            jr.setCode(500);
            jr.setMsg("网络炸了");
        }
        return jr;
    }

    /**
     * 根据企业名称查询所有数据
     * @return
     */
    @GetMapping("/findFirmCustomerByEnterpriseName")
    public JsonResult findFirmCustomerByEnterpriseName(Long currentPage, Long pageSize, String enterprise_name){
        return firmCustomerService.findFirmCustomerByEnterpriseName(currentPage,pageSize,enterprise_name);
    }

    /**
     * 根据id删除企业客户信息
     * @return
     */
    @GetMapping("/delFirmCustomerById")
    public R delFirmCustomerById(Integer id){
        return firmCustomerService.delFirmCustomerById(id);
    }

    /**
     * 添加企业客户信息
     * @return
     */
    @PostMapping("/addFirmCustomer")
    public R addFirmCustomer(@RequestBody Enterprise_Customer enterprise_customer){
        return firmCustomerService.addFirmCustomer(enterprise_customer);
    }

    /**
     * 修改企业客户信息
     * @return
     */
    @PostMapping("/updateFirmCustomer")
    public R updateFirmCustomer(@RequestBody Enterprise_Customer enterprise_customer){
        return firmCustomerService.updateFirmCustomer(enterprise_customer);
    }

    /**
     * 根据id查看客户信息
     * @return
     */
    @GetMapping("/queryFirmCustomerById")
    public R queryFirmCustomerById(Integer id){
        return firmCustomerService.queryFirmCustomerById(id);
    }
}
